function random(min,max){
return Math.random()*(max-min+1)+min
}
function getChar(){
return String.fromCharCode([
        Math.floor(random(0x109A0,0x109FF)),
        Math.floor(random(0x103A0,0x103DF)),
        Math.floor(random(0xA720,0xA7FF))
    ]
        [Math.floor(random(0,2))])
}

//画文字
function cxtText(text,i){
    // let fonts="欢迎来到LastYear的分享空间. . ."
    if(i>text.length+1){  
         
        return   
    }
   
    setTimeout(()=>{
        cxt.fillText(text.slice(0,i),innerWidth/2-110,100);
        i++
        cxtText(text,i)
    },200)
   
}

//画数字2
let tr=1
function cxtNumber2(font){
    let arr
    setInterval(()=>{
        if(tr){
            arr=Array(~~(innerWidth/font)).fill(0)
            tr=0
        }
        
        // canvas.style.background="rgba(0,0,0,0)"
        cxt.fillStyle="rgba(0,0,0,0.1)"
        cxt.font=`${font}px Georgia`;
        cxt.fillRect(0,0,canvas.width,canvas.height);


        // cxt.fillStyle="rgb(47,137,232)"
        // for(let i=0;i<5;i++){
        //     font=random(10,40)
        //     cxt.fillText(getChar(),random(0,canvas.width),random(0,canvas.height)) 

        // }

       
        cxt.fillStyle="green"
        arr.forEach((item,index)=>{ 
       
            cxt.fillText(getChar(),index*font,item) 
         
                arr[index]=Math.random()<0.01?0:item+font 
                
              
        })
    },50) 
}
            

//画数字1

function cxtNumber1(font,tr){
   
    let arr=Array(~~(innerWidth/font)).fill(0)
   let setinterval= setInterval(()=>{
    
        // canvas.style.background="rgba(0,0,0,0)"
        cxt.fillStyle="rgba(0,0,0,0.05 )"
        cxt.fillRect(0,0,canvas.width,canvas.height);
        arr.forEach((item,index)=>{ 
        cxt.fillStyle="green"
            cxt.fillText(getChar(),index*font,item)       
            arr[index]=item+font    
        })
    },40) 
    return setinterval
}

//开启
function off(){
    let a=cxtNumber1(font)
    setTimeout(()=>{
        clearInterval(a)
        cxtNumber2(font)
    },4000)
    
}


const canvas= document.querySelector("#canvas")
canvas.width=innerWidth
canvas.height=document.body.scrollHeight
const cxt=canvas.getContext("2d")
const font=12
cxt.font=`${font}px Georgia`;

//画文字
cxtText("欢迎来到LastYear的分享空间. . .",0)
off()
window.addEventListener("resize",function(){
    canvas.width=innerWidth
    canvas.height=document.body.scrollHeight
    tr=1
})